######################################################################
#Replication file for "The Impact of China's AIIB on the World Bank"
#Authors: Jing Qian, James Vreeland, Jianzhi Zhao
#Codes to replicate Figure G2
######################################################################
rm(list = ls())

#To install the bpCausal package (ver 0.0.1)
# install.packages('devtools', repos = 'http://cran.us.r-project.org') # if not already installed
# devtools::install_github('liulch/bpCausal')

#Load bpCausal package
library(bpCausal)

#Setwd
setwd("C:/Users/qianj/Dropbox (Princeton)/AIIB_WB_Replication")

#########################
#Estimation for Figure G.2
#########################
#----------------
#(1) Load result
#----------------
load("result/bpcausal_original.RData")
out1 = result.original

#########################
#Produce Figure G2
#########################
#Setup
png(filename = "figure/Figure_G2.png",
    height = 800,
    width = 1200)

par(mfrow = c(2, 5),
    mar = c(3, 3, 2, 1))

#Plot
for (i in 1:10){
  if (i == 1){
    plot(density(out1$wg[i,]),
         main = paste0("Factor", i),
         xlim = c(-1.5, 1.5))  
  } else if (i == 4){
    plot(density(out1$wg[i,]),
         main = paste0("Factor", i),
         xlim = c(-3, 3))
  } else {
    plot(density(out1$wg[i,]),
         main = paste0("Factor", i),
         xlim = c(-1, 1))
  }
}
#Close
dev.off()